package com.khmt2k3.xuantung.vnexpressnews;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;


public class VnexpressNewsActivity extends Activity 
{
	String[] title={"TRANG CHỦ","XÃ HỘI","THẾ GIỚI","KINH DOANH","VĂN HÓA",
			"THỂ THAO","PHÁP LUẬT","ĐỜI SỐNG","KHOA HỌC","VI TÍNH","Ô TÔ-XE MÁY",
			"BẠN ĐỌC","TÂM SỰ","CƯỜI"};
	String[] description={"Báo điện tử vnexpress.net"};
	
	String[] linkRSS={"http://vnexpress.net/rss/gl/trang-chu.rss","http://vnexpress.net/rss/gl/xa-hoi.rss","http://vnexpress.net/rss/gl/the-gioi.rss","http://vnexpress.net/rss/gl/kinh-doanh.rss",
			"http://vnexpress.net/rss/gl/van-hoa.rss","http://vnexpress.net/rss/gl/the-thao.rss","http://vnexpress.net/rss/gl/phap-luat.rss","http://vnexpress.net/rss/gl/doi-song.rss",
			"http://vnexpress.net/rss/gl/khoa-hoc.rss","http://vnexpress.net/rss/gl/vi-tinh.rss","http://vnexpress.net/rss/gl/oto-xe-may.rss","http://vnexpress.net/rss/gl/ban-doc-viet.rss",
			"http://vnexpress.net/rss/gl/ban-doc-viet-tam-su.rss","http://vnexpress.net/rss/gl/cuoi.rss"};
	
	final int numCategory=14; //So muc. lay tin 

			
	ListView listView_Menu;
	ArrayList<Menu>listMenu=new ArrayList<Menu>();	
	
	public static ParserRSS parserRSS;
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        listView_Menu=(ListView)findViewById(R.id.listview_menu);        
        loadInitial();
        
        AdapterMenu adapter=new AdapterMenu(listMenu, getApplicationContext());
        listView_Menu.setAdapter(adapter);
       
      
        listView_Menu.setOnItemClickListener(new OnItemClickListener() 
        {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
			{
				Intent intent=new Intent("com.khmt2k3.xuantung.demorss.listnewsactivity");
				
				Bundle bundle=new Bundle();
				bundle.putString("linkRSS", listMenu.get(arg2).getLinkRSS());				
			
				intent.putExtras(bundle);
				startActivityForResult(intent,1);
			}
		});
        
       
    }
    
    /**
     * Load cac' title, description len listview menu
     */    
    private void loadInitial()
    {
    	for(int i=0;i<numCategory;i++)
    	{
    		Menu menu=new Menu(title[i], description[0], R.drawable.rss, linkRSS[i]);
    		listMenu.add(menu);
    	}
    			
    }
 
}
